package com.yikaiye.android.yikaiye.ui.fragment;

import android.view.View;

import com.yikaiye.android.yikaiye.base.BaseFragment;
import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.databinding.FragmentServiceCorrelationBinding;
import com.yikaiye.android.yikaiye.model.ServiceRecordsModel;
import com.yikaiye.android.yikaiye.ui.adapter.CorrelationServiceAdapter;
import com.yikaiye.android.yikaiye.widget.AutoHeightViewPager;

import java.util.List;

/**
 * 相关服务
 */
public class CorrelationServiceFragment extends BaseFragment<FragmentServiceCorrelationBinding, BaseViewModel> {

    private final AutoHeightViewPager viewPager;
    private final List<ServiceRecordsModel.ServiceModel> relServiceList;

    @Override
    protected BaseViewModel bindModel() {
        return getViewModel(this, BaseViewModel.class);
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    protected void initData() {
        viewPager.setObjectForPosition(binding.getRoot(), 2);//2代表tab的位置
        if (relServiceList!=null && !relServiceList.isEmpty()) {
            CorrelationServiceAdapter adapter = new CorrelationServiceAdapter(mContext);
            binding.recyclerView.setAdapter(adapter);
            adapter.submitList(relServiceList);
        } else {
            binding.recyclerView.setVisibility(View.GONE);
            binding.noDataTv.setVisibility(View.VISIBLE);
        }
    }

    public CorrelationServiceFragment(AutoHeightViewPager viewPager, List<ServiceRecordsModel.ServiceModel> relServiceList) {
        this.viewPager = viewPager;
        this.relServiceList = relServiceList;
    }

    public static CorrelationServiceFragment newInstance(AutoHeightViewPager viewPager, List<ServiceRecordsModel.ServiceModel> relServiceList) {
        return new CorrelationServiceFragment(viewPager, relServiceList);
    }
}
